#below will create default markdown parser

import markdown
from markdown.treeprocessors import Treeprocessor
from markdown.extensions import Extension
from markdown.util import etree
class ReFactorTree(Treeprocessor):
    def run(self, root):
        #~ import xml.etree.ElementTree as etree
        #~ print(type(root))
        import copy
        newroot=etree.Element('div')

        e=root.find('div[@class="toc"]')
        if e is not None:
            newroot.append(e)
            root.remove(e)

        #~ body_top=etree.Element('div',attrib={'class':'container'})
        #~ body_top.append(root)
        root.attrib['class']='markdown-body'
        newroot.append(root)

        return newroot #tree won't be modified
class RefactorExtension (Extension):
    """ Meta-Data extension for Python-Markdown. """

    def extendMarkdown(self, md, md_globals):
        """ Add MetaPreprocessor to Markdown instance. """
        md.treeprocessors.add("jywiki", ReFactorTree(), "_end")
import markdown.util as util


from .exts.include import MarkdownInclude
def get_markdown_parser(file_path=None,siteurl=None,outpath=None,**kwargs):
    extensions=[
            'markdown.extensions.fenced_code',
            'markdown.extensions.meta',
            'markdown.extensions.tables',
            'markdown.extensions.toc',
            'pymdownx.arithmatex',
            'markdown.extensions.codehilite',
            __package__ + '.exts.grid_tables',
            __package__ + '.exts.plantuml',
            __package__ + '.exts.macro',
            ]
    if file_path is not None:
        extensions.append(
            MarkdownInclude(configs={'base_path':file_path,
            'encoding': 'utf-8'}))
    extensions.append(RefactorExtension())
    #~ print(extensions)
    m=markdown.Markdown(extensions=extensions,
            extension_configs={
            'markdown.extensions.codehilite':{'guess_lang':False},
            __package__ + '.exts.plantuml':{'format':'svg_inline'
                },
            })
    m.stripTopLevelTags=False

    return m
